import re

def clean_index_html_from_app():
    app_path = 'd:/new/phthon_3/app.py'
    
    with open(app_path, 'r', encoding='utf-8') as file:
        content = file.read()
    
    # 匹配INDEX_HTML模板定义及其内容
    pattern = r'# HTML 模板\nINDEX_HTML = \'\'\'[\s\S]*?\'\'\'(?=\n)'
    
    # 统计替换前的字符数
    original_length = len(content)
    
    # 替换
    new_content = re.sub(pattern, '# HTML模板已移除，现在使用index.html文件', content)
    
    # 统计替换后的字符数
    new_length = len(new_content)
    
    # 写回文件
    with open(app_path, 'w', encoding='utf-8') as file:
        file.write(new_content)
    
    removed_chars = original_length - new_length
    return {
        'status': 'success',
        'file': app_path,
        'removed_chars': removed_chars,
        'message': f'成功从app.py移除INDEX_HTML模板字符串，减少了{removed_chars}个字符'
    }

if __name__ == '__main__':
    result = clean_index_html_from_app()
    print(result['message'])
